import { Component } from "@angular/core";
import {
  IonicPage,
  NavController,
  NavParams,
  ToastController,
  App
} from "ionic-angular";
import { TeamSeriveProvider } from "../../../../../providers/team-serive/team-serive";
import { BaseUI } from "../../../../../common/baseUI";
import { PcSeriveProvider } from "../../../../../providers/pc-serive/pc-serive";
/**
 * Generated class for the MemberDetailsPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: "page-member-details",
  templateUrl: "member-details.html"
})
export class MemberDetailsPage extends BaseUI {
  //qq号码
  qqNumber: string;
  //姓名
  nickName: string;
  //班级
  class: string;
  //用户头像
  userImgUrl: string;
  //用户名
  realname: string;
  //背景地址数组
  backImgs = [];
  baImgUrl;
  // bgUrl: string;
  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    public teamSeriveProvider: TeamSeriveProvider,
    public toastCtrl: ToastController,
    public app: App,
    public pcSeriveProvider: PcSeriveProvider
  ) {
    super();
    this.backImgs = [
      "http://netx-check.oss-cn-shenzhen.aliyuncs.com/photo/1533191152234.png",
      "http://netx-check.oss-cn-shenzhen.aliyuncs.com/photo/1533191257144.png",
      "http://netx-check.oss-cn-shenzhen.aliyuncs.com/photo/1533191273642.png",
      "http://netx-check.oss-cn-shenzhen.aliyuncs.com/photo/1533191291941.png",
      "http://netx-check.oss-cn-shenzhen.aliyuncs.com/photo/1533191306663.png",
      "http://netx-check.oss-cn-shenzhen.aliyuncs.com/photo/1533191333909.png",
      "http://netx-check.oss-cn-shenzhen.aliyuncs.com/photo/1533191352787.png",
      "http://netx-check.oss-cn-shenzhen.aliyuncs.com/photo/1533191367341.png",
      "http://netx-check.oss-cn-shenzhen.aliyuncs.com/photo/1533191376090.png",
      "http://netx-check.oss-cn-shenzhen.aliyuncs.com/photo/1533191388739.png",
      "http://netx-check.oss-cn-shenzhen.aliyuncs.com/photo/1533191406030.png",
      "http://netx-check.oss-cn-shenzhen.aliyuncs.com/photo/1533191415413.png",
      "http://netx-check.oss-cn-shenzhen.aliyuncs.com/photo/1533191426298.png",
      "http://netx-check.oss-cn-shenzhen.aliyuncs.com/photo/1533191445077.png",
      "http://netx-check.oss-cn-shenzhen.aliyuncs.com/photo/1533191457567.png",
      "http://netx-check.oss-cn-shenzhen.aliyuncs.com/photo/1533191468875.png"
    ];

    // this.bgUrl = this.pcSeriveProvider.imgdate[Math.floor(Math.random() * 14 + 1)];console.log(this.bgUrl);
    this.teamSeriveProvider
      .getUserInfo(this.navParams.get("item").usercode)
      .subscribe(
        data => {
          if (data["status"] == 500) {
            super.showToast(this.toastCtrl, "登录失效，请重新登录");
            this.app.getRootNav().setRoot("LoginOrRegisterPage");
            return;
          }
          this.qqNumber = data["userqq"];
          this.nickName = data["nickname"];
          this.class = data["classes"];
          this.userImgUrl = data["avatar"];
          this.realname = data["realname"];
        },
        err => {
          super.showToast(this.toastCtrl, "请求数据失败，请重试");
        }
      );
  }

  ionViewDidLoad() {
    this.baImgUrl = this.backImgs[Math.floor(Math.random() * this.backImgs.length)];
  }

  //返回
  back() {
    this.navCtrl.pop();
  }
}
